package action;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import action.support.excel.ExcelUtil;
import action.support.excel.Poi;

@Controller
@Scope("request")
public class ExportAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4614159361434927788L;
	private HttpServletRequest request;
	private String excelName;
	private InputStream excelStream;

	public String index() throws IOException {
		request = ServletActionContext.getRequest();
		String json = request.getParameter("excel_json");
		System.out.println(json);
		String[][] data = ExcelUtil.jsonToArray(json,fs);
		Poi poi = new Poi();
		poi.createExcel();
		poi.fromStringArray(data);
		setExcelStream(poi.toInputStream());
		setExcelName("export.xlsx");
		return SUCCESS;
	}

	public InputStream getExcelStream() {
		return excelStream;
	}
	public void setExcelStream(InputStream excelStream) {
		this.excelStream = excelStream;
	}

	public String getExcelName() {
		return excelName;
	}

	public void setExcelName(String excelName) {
		this.excelName = excelName;
	}
}
